import 'package:flutter/material.dart';
import 'package:pabu/widget/plugin/markdown/markdown_page.dart';
import 'package:pabu/widget/plugin/radialmenu/radialmenu_page.dart';
import 'package:pabu/widget/plugin/sundry/sundry_page.dart';
import 'package:pabu/widget/plugin/swiper/swiper_page.dart';

class PluginPage extends StatefulWidget {
  @override
  _PluginPageState createState() => new _PluginPageState();
}

class _PluginPageState extends State<PluginPage> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("Request"),
        ),
        body: _buildListView(),
      ),
    );
  }

  Widget _buildListView() {
    return ListView.builder(
      itemBuilder: (context, index) {
        return _buildListViewItem(index);
      },
      itemCount: components.length,
    );
  }

  Widget _buildListViewItem(index) {
    return GestureDetector(
      child: Container(
        padding: EdgeInsets.all(15.0),
        decoration: BoxDecoration(
            border: Border(bottom: BorderSide(color: Colors.white70))),
        child: Column(
          children: <Widget>[
            Container(
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Container(
                    child: Row(
                      children: <Widget>[
                        Text(components[index].name),
                      ],
                    ),
                  ),
                  Container(
                    child: Icon(Icons.arrow_forward_ios),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
      onTap: () {
        _pushPage(index);
      },
    );
  }

  void _pushPage(index) {
    Navigator.push(
      context,
      new MaterialPageRoute(builder: (context) => components[index].page),
    );
  }

}
class Component {
  Component({this.ukId, this.name, this.page});

  String ukId;
  String name;
  Widget page;
}

List<Component> components = <Component>[
  Component(ukId: "1", name: "轮播图", page: new SwiperPage()),
  Component(ukId: "2", name: "杂项", page: new SundryPage()),
  Component(ukId: "2", name: "视频", page: new SundryPage()),
  Component(ukId: "2", name: "markdown", page: new MarkdownPage()),
  Component(ukId: "2", name: "RdialMenu", page: new RdialMenuPage()),
  Component(ukId: "2", name: "数据库", page: new SundryPage()),
];
